﻿Public Class StatPlots
    Public Function HistoGram(ByVal input() As Double, ByVal interval As Double) As Double(,)
        If input.Min = input.Max Then
            MsgBox("array max and min are same")
            Exit Function
        End If
        Array.Sort(input)
        Dim ymat() As Integer
        Dim xmat() As Double

        Dim size As Double = input.Min
        Dim count As Double = 0
        Do While size < input.Max
            ReDim Preserve xmat(count)
            ReDim ymat(count)
            size = size + interval
            xmat(count) = size
            count = count + 1
        Loop

        For i As Integer = 0 To input.GetLength(0) - 1
            For j As Integer = 0 To xmat.GetLength(0) - 1
                If input(i) <= xmat(j) Then
                    ymat(j) = ymat(j) + 1
                    Exit For
                End If
            Next
        Next

        Dim return_array(xmat.GetLength(0) - 1, 1) As Double
        For i As Integer = 0 To return_array.GetLength(0) - 1
            return_array(i, 0) = xmat(i)
            return_array(i, 1) = ymat(i)
        Next
        Return return_array
    End Function

End Class